package com.atgouwu.mall.product.service.impl;

import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atgouwu.mall.common.utils.PageUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.atgouwu.mall.product.dao.BrandDao;
import com.atgouwu.mall.product.entity.BrandEntity;
import com.atgouwu.mall.product.service.BrandService;

@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BrandEntity> page = this.page(
                new Page<>(Long.valueOf(String.valueOf(params.get("page"))), Long.valueOf(String.valueOf(params.get("size")))),
                new QueryWrapper<BrandEntity>()
        );
        return new PageUtils(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
    }

    //获取品牌
    @Override
    public List<BrandEntity> brandList(String sortField, Integer limit) {
        List<BrandEntity> brandList = baseMapper.selectList(new QueryWrapper<BrandEntity>().orderByAsc(sortField).last("limit 0," + limit));
        return brandList;
    }

}